package com.hontech.kaltaapp.device.codec

import com.hontech.kaltaapp.utils.toU8

class ByteView(var buf: ByteArray = byteArrayOf(), var index: Int = 0, var len: Int = buf.size - index) : CodecType {

    override fun encode(buf: ByteArray, index: Int) {
        buf[index] = this.len.toByte()
        System.arraycopy(this.buf, this.index, buf, index + 1, this.len)
    }

    override fun decode(buf: ByteArray, index: Int) {
        this.buf = buf
        this.index = index + 1
        this.len = buf[index].toU8()
    }

    override fun size(): Int {
        return 1 + this.len
    }

    override fun toString(): String {
        return String(buf, index, len)
    }
}



